<template>
  <el-card shadow="never">
    <e-table
      ref="eTable"
      @getList="handleGetList"
      :tableData="tableData"
      :columns="columns"
      :loading="loading"
      :pageObj="null"
    >
      <el-table-column label="性别" slot="sex" align="center">
        <template slot-scope="scope">{{ scope.row.sex === '0' ? '男' : '女' }}</template>
      </el-table-column>
      <el-table-column slot="action" fixed="right" width="50" align="center">
        <template slot-scope="scope">
          <el-dropdown>
            <a class="el-dropdown-link">
              <i class="el-icon-menu"></i>
            </a>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="handleCheck(true, scope.row)">
                <a class="green">审核通过</a>
              </el-dropdown-item>
              <el-dropdown-item @click.native="handleCheck(false, scope.row)">
                <a class="red">审核不通过</a>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </e-table>
  </el-card>
</template>

<script>
import { getUserInfoVerify, verifyUserInfo } from '@/api/archives'
import { openNotification } from '@/utils/util'

export default {
  data() {
    return {
      loading: false,
      tableData: [],
      columns: [
        {
          label: '工号',
          prop: 'employeeId'
        },
        {
          label: '姓名',
          prop: 'name'
        },
        { slot: 'sex' },
        {
          label: '婚姻状况',
          prop: 'marryStatusName'
        },
        {
          label: '出生年月',
          prop: 'birth'
        },
        {
          label: '身份证号',
          prop: 'idCard',
          width: '140px'
        },
        {
          label: '职称',
          prop: 'jobTitle'
        },
        {
          label: '民族',
          prop: 'nationName'
        },
        {
          label: '籍贯',
          prop: 'nativePlaceName'
        },
        {
          label: '工作电话',
          prop: 'workTel'
        },
        { slot: 'action' }
      ],
      queryParam: {
        pageSize: 10,
        pageNo: 1
      }
    }
  },
  mounted() {
    this.handleGetList()
  },
  methods: {
    //columns 动态删减，根据form传递过来的数据
    async handleGetList(param = {}) {
      this.loading = true
      this.queryParam = Object.assign(this.queryParam, param)

      const res = await getUserInfoVerify(this.queryParam)
      if (res && res.data.length > 0) {
        const { state, data } = res
        this.tableData = data
      } else {
        this.tableData = []
      }
      this.loading = false
    },
    handleCheck(check, row) {
      console.log('')
      const { userInfoId, verifyStatus } = row
      let param = { userInfoId, verifyStatus }
      let mes = null
      if (check) {
        param.state = 1
        mes = '审核通过操作成功'
      } else {
        param.state = 0
        mes = '审核不通过操作成功'
      }
      verifyUserInfo(param).then(res => {
        console.log('res', res)
        if (res.state === '000000') {
          openNotification('success', mes)
          this.handleGetList()
        }
      })
    }
  }
}
</script>
